import java.lang.StringBuilder;
public class Solution{
    public static void main(String[] args){
        Solution solution =new Solution();
        String s = "ABCDE";
        int nRows = 4;
        System.out.println(solution.convert(s,nRows));
    }
    public String convert(String s, int numRows) {
        int length = s.length();
        // System.out.println(length);
        if (length<=numRows||numRows<2){
            return s;
        }
        StringBuilder sb = new StringBuilder();
        for (int i =0;i<numRows;i++){
            for(int j=i;j<length;j=j+numRows+numRows-2){
                System.out.println(s.charAt(j));
                sb.append(s.charAt(j));
                if (i!=0&&i!=numRows-1){
                    int mid = j+((numRows-i-1)*2);
                    System.out.print(mid);
                    if(mid<length){
                        
                        System.out.println(s.charAt(mid));
                        sb.append(s.charAt(mid));
                }
                }
                
            }
        }
        return sb.toString();
    }
}